import { message } from 'ant-design-vue'
import notification from 'ant-design-vue/es/notification'

const Message: any = (options: any) => {
	;(message as any).destroy()
	;(message as any)[options.type](options)
}

const Notification: any = (options: any) => {
	;(notification as any).destroy()
	;(notification as any)[options.type](options)
}

;['success', 'info', 'warning', 'error', 'loading'].forEach(type => {
	Message[type] = (options: any) => {
		if (typeof options === 'string') {
			options = {
				content: options
			}
		}
		options.type = type
		return Message(options)
	}
})
;['success', 'info', 'warning', 'error', 'loading', 'warn', 'open'].forEach(type => {
	Notification[type] = (options: any) => {
		if (typeof options === 'string') {
			options = {
				message: '温馨提示',
				description: options
			}
		}
		options.type = type
		return Notification(options)
	}
})

export { Message, Notification }
